package com.ershijin.resourceserver.web;

import com.ershijin.common.entity.User;
import com.ershijin.common.util.JsonUtils;
import com.ershijin.common.util.UserUtils;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ArticlesController {

    @GetMapping("/articles")
    public String[] getArticles() {
        System.out.println("-----------------------");
        SecurityContext context = SecurityContextHolder.getContext();

        User currentUser = UserUtils.getCurrentUser();
        System.out.println(currentUser);

        System.out.println("..........................");
        return new String[]{"Article 1", "Article 2", "Article 3", JsonUtils.toJsonString(currentUser)};
    }

    @GetMapping("/callback")
    public String callback() {
        return "callback";
    }
}